load("//bazel:mongo_src_rules.bzl", "mongo_cc_library")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

cc_library(
    name = "mongo_tidy_checks_static",
    srcs = [
        "MongoAssertCheck.cpp",
        "MongoCctypeCheck.cpp",
        "MongoCollectionShardingRuntimeCheck.cpp",
        "MongoConfigHeaderCheck.cpp",
        "MongoCxx20BannedIncludesCheck.cpp",
        "MongoCxx20StdChronoCheck.cpp",
        "MongoFCVConstantCheck.cpp",
        "MongoHeaderBracketCheck.cpp",
        "MongoInvariantStatusIsOKCheck.cpp",
        "MongoMacroDefinitionLeaksCheck.cpp",
        "MongoNoUniqueAddressCheck.cpp",
        "MongoPolyFillCheck.cpp",
        "MongoRWMutexCheck.cpp",
        "MongoRandCheck.cpp",
        "MongoStdAtomicCheck.cpp",
        "MongoStdOptionalCheck.cpp",
        "MongoStringDataConstRefCheck.cpp",
        "MongoTidyModule.cpp",
        "MongoTraceCheck.cpp",
        "MongoUninterruptibleLockGuardCheck.cpp",
        "MongoUnstructuredLogCheck.cpp",
        "MongoVolatileCheck.cpp",
    ],
    hdrs = [
        "MongoAssertCheck.h",
        "MongoCctypeCheck.h",
        "MongoCollectionShardingRuntimeCheck.h",
        "MongoConfigHeaderCheck.h",
        "MongoCxx20BannedIncludesCheck.h",
        "MongoCxx20StdChronoCheck.h",
        "MongoFCVConstantCheck.h",
        "MongoHeaderBracketCheck.h",
        "MongoInvariantStatusIsOKCheck.h",
        "MongoMacroDefinitionLeaksCheck.h",
        "MongoNoUniqueAddressCheck.h",
        "MongoPolyFillCheck.h",
        "MongoRWMutexCheck.h",
        "MongoRandCheck.h",
        "MongoStdAtomicCheck.h",
        "MongoStdOptionalCheck.h",
        "MongoStringDataConstRefCheck.h",
        "MongoTidyUtils.h",
        "MongoTraceCheck.h",
        "MongoUninterruptibleLockGuardCheck.h",
        "MongoUnstructuredLogCheck.h",
        "MongoVolatileCheck.h",
    ],
    copts = [
        "-Isrc/mongo/tools/mongo_tidy_checks/",  # Ensures that `#include "Mongo..."` calls continue to work in Bazel AND in SCons
        "-Iexternal/mongo_toolchain/stow/llvm-v4/include",  # Ensures that `#include "clang-tidy/*` directives work.
        "-DNDEBUG",
        "-Wall",
        "-fdiagnostics-color",
        "-ffunction-sections",
        "-fno-common",
        "-fno-exceptions",
        "-fno-rtti",
        "-fno-strict-aliasing",
        "-fPIC",
        "-fvisibility-inlines-hidden",
        "-g2",
        "-O3",
        "-pedantic",
        "-std=c++17",
        "-Wcast-qual",
        "-Wdelete-non-virtual-dtor",
        "-Werror=date-time",
        "-Wextra",
        "-Wimplicit-fallthrough",
        "-Wno-class-memaccess",
        "-Wno-comment",
        "-Wno-long-long",
        "-Wno-maybe-uninitialized",
        "-Wno-missing-field-initializers",
        "-Wno-noexcept-type",
        "-Wno-redundant-move",
        "-Wno-unused-parameter",
        "-Woverloaded-virtual",
        "-Wwrite-strings",
        "-Wsuggest-override",
    ],
    local_defines = [
        "GTEST_HAS_RTTI=0",
        "_GNU_SOURCE",
        "__STDC_CONSTANT_MACROS",
        "__STDC_FORMAT_MACROS",
        "__STDC_LIMIT_MACROS",
    ],
    tags = [
        "mongo-tidy-checks",
    ],
    target_compatible_with = select({
        "@platforms//os:windows": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    deps = [],
)

cc_shared_library(
    name = "mongo_tidy_checks",
    additional_linker_inputs = [],
    dynamic_deps = [],
    tags = [
        "mongo-tidy-checks",
    ],
    user_link_flags = [
        "-DNDEBUG",
        "-fPIC",
        "-fvisibility-inlines-hidden",
        "-fdata-sections",
        "-fdiagnostics-color",
        "-ffunction-sections",
        "-fno-common",
        "-fno-strict-aliasing",
        "-O3",
        "-pedantic",
        "-shared",
        "-Wall",
        "-Werror=date-time",
        "-Wextra",
        "-Woverloaded-virtual",
        "-Wno-unused-parameter",
        "-Wwrite-strings",
        "-Wcast-qual",
        "-Wno-missing-field-initializers",
        "-Wno-long-long",
        "-Wimplicit-fallthrough",
        "-Wno-maybe-uninitialized",
        "-Wno-class-memaccess",
        "-Wno-redundant-move",
        "-Wno-noexcept-type",
        "-Wdelete-non-virtual-dtor",
        "-Wsuggest-override",
        "-Wno-comment",
        "-Wl,-z,nodelete",
        "-Wl,-rpath-link,external/mongo_toolchain/stow/llvm-v4/lib",
        "-Wl,-O3",
        "-Wl,--gc-sections",
        "-Wl,-rpath,\\$ORIGIN/../lib",  # Ensure that the shared library can find its dependencies.
    ],
    deps = [
        ":mongo_tidy_checks_static",
    ],
)
